package com.bootdo.blog.dao;

import com.bootdo.blog.domain.DrugDO;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-06 21:38:13
 */
@Mapper
public interface DrugMapper {

	@Select("select `drug_id`, `batch`, `does_time`, `varieties`, `disease`, `duration_time`, `dosage`, `count`, `principal`, `telephone` from tb_drug where drug_id = #{id}")
	DrugDO get(Integer drugId);
	
	@Select("<script>" +
	"select * from tb_drug " + 
			"<where>" + 
		  		  "<if test=\"drugId != null and drugId != ''\">"+ "and drug_id = #{drugId} " + "</if>" + 
		  		  "<if test=\"batch != null and batch != ''\">"+ "and batch = #{batch} " + "</if>" + 
		  		  "<if test=\"doesTime != null and doesTime != ''\">"+ "and does_time = #{doesTime} " + "</if>" + 
		  		  "<if test=\"varieties != null and varieties != ''\">"+ "and varieties = #{varieties} " + "</if>" + 
		  		  "<if test=\"disease != null and disease != ''\">"+ "and disease = #{disease} " + "</if>" + 
		  		  "<if test=\"durationTime != null and durationTime != ''\">"+ "and duration_time = #{durationTime} " + "</if>" + 
		  		  "<if test=\"dosage != null and dosage != ''\">"+ "and dosage = #{dosage} " + "</if>" + 
		  		  "<if test=\"count != null and count != ''\">"+ "and count = #{count} " + "</if>" + 
		  		  "<if test=\"principal != null and principal != ''\">"+ "and principal = #{principal} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  			"</where>"+ 
			" <choose>" + 
	            "<when test=\"sort != null and sort.trim() != ''\">" + 
	                "order by ${sort} ${order}" + 
	            "</when>" + 
				"<otherwise>" + 
	                "order by drug_id desc" + 
				"</otherwise>" + 
	        "</choose>"+
			"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+
			"</script>")
	List<DrugDO> list(Map<String, Object> map);
	
	@Select("<script>" +
	"select count(*) from tb_drug " + 
			"<where>" + 
		  		  "<if test=\"drugId != null and drugId != ''\">"+ "and drug_id = #{drugId} " + "</if>" + 
		  		  "<if test=\"batch != null and batch != ''\">"+ "and batch = #{batch} " + "</if>" + 
		  		  "<if test=\"doesTime != null and doesTime != ''\">"+ "and does_time = #{doesTime} " + "</if>" + 
		  		  "<if test=\"varieties != null and varieties != ''\">"+ "and varieties = #{varieties} " + "</if>" + 
		  		  "<if test=\"disease != null and disease != ''\">"+ "and disease = #{disease} " + "</if>" + 
		  		  "<if test=\"durationTime != null and durationTime != ''\">"+ "and duration_time = #{durationTime} " + "</if>" + 
		  		  "<if test=\"dosage != null and dosage != ''\">"+ "and dosage = #{dosage} " + "</if>" + 
		  		  "<if test=\"count != null and count != ''\">"+ "and count = #{count} " + "</if>" + 
		  		  "<if test=\"principal != null and principal != ''\">"+ "and principal = #{principal} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  			"</where>"+ 
			"</script>")
	int count(Map<String, Object> map);
	
	@Insert("insert into tb_drug (`batch`, `does_time`, `varieties`, `disease`, `duration_time`, `dosage`, `count`, `principal`, `telephone`)"
	+ "values (#{batch}, #{doesTime}, #{varieties}, #{disease}, #{durationTime}, #{dosage}, #{count}, #{principal}, #{telephone})")
	int save(DrugDO drug);
	
	@Update("<script>"+ 
			"update tb_drug " + 
					"<set>" + 
		            "<if test=\"drugId != null\">`drug_id` = #{drugId}, </if>" + 
                    "<if test=\"batch != null\">`batch` = #{batch}, </if>" + 
                    "<if test=\"doesTime != null\">`does_time` = #{doesTime}, </if>" + 
                    "<if test=\"varieties != null\">`varieties` = #{varieties}, </if>" + 
                    "<if test=\"disease != null\">`disease` = #{disease}, </if>" + 
                    "<if test=\"durationTime != null\">`duration_time` = #{durationTime}, </if>" + 
                    "<if test=\"dosage != null\">`dosage` = #{dosage}, </if>" + 
                    "<if test=\"count != null\">`count` = #{count}, </if>" + 
                    "<if test=\"principal != null\">`principal` = #{principal}, </if>" + 
                    "<if test=\"telephone != null\">`telephone` = #{telephone}, </if>" + 
          					"</set>" + 
					"where drug_id = #{drugId}"+
			"</script>")
	int update(DrugDO drug);
	
	@Delete("delete from tb_drug where drug_id =#{drugId}")
	int remove(Integer drug_id);
	
	@Delete("<script>"+ 
			"delete from tb_drug where drug_id in " + 
					"<foreach item=\"drugId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" + 
						"#{drugId}" + 
					"</foreach>"+
			"</script>")
	int batchRemove(Integer[] drugIds);
}
